
*Settings
clear all
cap log close
*Change this to your system name
local user "awcassidy1"
set more off, permanently
cd "C:\Users\awcassidy1\Dropbox\jmp_new\cleaned_data"


use "C:\Users\awcassidy1\Dropbox\jmp_new\cleaned_data/data_with_observability_indices.dta", clear




********************************************************************************
*Baseline: observability groups
********************************************************************************
*standard values
local clustvar "mlsid"
local clustvarword "Home"
local fevars "i.saleyear i.lsaleyear i.yearbuiltcat"
local fe_to_absorb="saleyear lsaleyear yearbuiltcat"
local controls "yearbuiltaudit conditionedsqft"
local baselinevars "parsimonious_less parsimonious_more_fuel parsimonious_more_other"
local filename "main"
local depvar "pricediff"
local not_extracted="duct_type  rsavg  eeravg  sizeavg    negsysageavg ah_type notwinrec  notraddr"

local parsimonious_less_vars "negleakavg atticrvalue ductravg     "
local parsimonious_more_vars_fuel "fftype whftype "
local parsimonious_more_vars_other "ah_location progtherm twosystems"


********************************************************************************
*VAR DEFINITIONS AND LABELS
********************************************************************************
gen pre_above_med_ee=above_median_ee_all_mean*pre
gen post_above_med_ee= above_median_ee_all_mean*post
la var pre_above_med_ee "Above Med EE $\times$ Sale -2"
la var post_above_med_ee "Above Med EE $\times$ Sale 0"
la var above_median_ee_all_mean "Above Med EE"
la var above_median_less "Above Med Less"

gen pre_above_med_less=above_median_less*pre
gen post_above_med_less= above_median_less*post
la var pre_above_med_less "Above Med Less $\times$ Sale -2"
la var post_above_med_less "Above Med Less $\times$ Sale 0"

gen pre_Less_st = Less_st*pre
gen post_Less_st = Less_st*post
la var pre_Less_st "Less $\times$ Sale -2"
la var post_Less_st "Less $\times$ Sale 0"

gen pre_More_Fuel_st = More_Fuel_st*pre
gen post_More_Fuel_st = More_Fuel_st*post
la var pre_More_Fuel_st "More-Fuel $\times$ Sale -2"
la var post_More_Fuel_st "More-Fuel $\times$ Sale 0"

gen pre_More_Other_st = More_Other_st*pre
gen post_More_Other_st = More_Other_st*post
la var pre_More_Other_st "More-Other $\times$ Sale -2"
la var post_More_Other_st "More-Other $\times$ Sale 0"


	
*********************************************************************************
**Regression of price on 3 components of energy efficiency separately  (Table 2)
*********************************************************************************

		
		
eststo clear
*Main
eststo: reghdfe pricediff Less_st  ///
	///
	, ///
		vce(cl mlsid) absorb(yearbuiltcat saleyear lsaleyear )	

estadd scalar r2all = e(r2)

		
estadd local sample="\multicolumn{1}{c}{Main}"
estadd local dep_var = "\multicolumn{1}{c}{$\Delta$ P}"
estadd local stdzd = "\multicolumn{1}{c}{Yes}"
estadd local control_yblt_sqft =  "\multicolumn{1}{c}{No}"


eststo: reghdfe pricediff  More_Fuel_st  ///
	///
	, ///
		vce(cl mlsid) absorb(yearbuiltcat saleyear lsaleyear )	

estadd scalar r2all = e(r2)

		
estadd local sample="\multicolumn{1}{c}{Main}"
estadd local dep_var = "\multicolumn{1}{c}{$\Delta$ P}"
estadd local stdzd = "\multicolumn{1}{c}{Yes}"
estadd local control_yblt_sqft =  "\multicolumn{1}{c}{No}"




eststo: reghdfe pricediff More_Other_st ///
	///
	, ///
		vce(cl mlsid) absorb(yearbuiltcat saleyear lsaleyear )	

estadd scalar r2all = e(r2)

estadd local sample="\multicolumn{1}{c}{Main}"
estadd local dep_var = "\multicolumn{1}{c}{$\Delta$ P}"
estadd local stdzd = "\multicolumn{1}{c}{Yes}"
estadd local control_yblt_sqft =  "\multicolumn{1}{c}{No}"




local keepvars Less_st /// 
		 More_Fuel_st  ///
		 More_Other_st 
		 
esttab using "C:\Users\awcassidy1\Dropbox\jmp_new/tables/main_main.tex", replace fragment ///
		keep(`keepvars') order(`keepvars') ///
		 label booktabs nomtitles noobs se(4) b(4) ///
		scalars( ///
				"r2all R-squared" ///
			 "N Observations"  ///
				) ///
				sfmt( %9.3fc %9.0fc  %9.0fc ) star(* 0.10 ** 0.05 *** 0.01)
				

********************************************************************************
*Regression of price on 3 components of energy efficiency together  (Table 3)
********************************************************************************
eststo clear


eststo: reghdfe pricediff Less_st More_Fuel_st More_Other_st ///
	///
	, ///
		vce(cl mlsid) absorb(yearbuiltcat saleyear lsaleyear )	

estadd scalar r2all = e(r2)

test _b[Less_st] = _b[More_Fuel_st]

estadd local sample="\multicolumn{1}{c}{Main}"
estadd local dep_var = "\multicolumn{1}{c}{$\Delta$ P}"
estadd local stdzd = "\multicolumn{1}{c}{Yes}"
estadd local control_yblt_sqft =  "\multicolumn{1}{c}{No}"
estadd local control_not_extracted =  "\multicolumn{1}{c}{No}"
estadd local control_wh_tanktype =  "\multicolumn{1}{c}{No}"

eststo: reghdfe pricediff Less_st More_Fuel_st More_Other_st ///
	yearbuiltaudit_st conditionedsqft_st ///
	, ///
		vce(cl mlsid) absorb(yearbuiltcat saleyear lsaleyear )	

estadd scalar r2all = e(r2)


estadd local sample="\multicolumn{1}{c}{Main}"
estadd local dep_var = "\multicolumn{1}{c}{$\Delta$ P}"
estadd local stdzd = "\multicolumn{1}{c}{Yes}"
estadd local control_yblt_sqft =  "\multicolumn{1}{c}{Yes}"
estadd local control_not_extracted =  "\multicolumn{1}{c}{No}"
estadd local control_wh_tanktype =  "\multicolumn{1}{c}{No}"



eststo: reghdfe pricediff Less_st More_Fuel_st More_Other_st ///
	yearbuiltaudit_st conditionedsqft_st ///
	`not_extracted' ///
	, ///
		vce(cl mlsid) absorb(yearbuiltcat saleyear lsaleyear )	

estadd scalar r2all = e(r2)


estadd local sample="\multicolumn{1}{c}{Main}"
estadd local dep_var = "\multicolumn{1}{c}{$\Delta$ P}"
estadd local stdzd = "\multicolumn{1}{c}{Yes}"
estadd local control_yblt_sqft =  "\multicolumn{1}{c}{Yes}"
estadd local control_not_extracted =  "\multicolumn{1}{c}{Yes}"
estadd local control_wh_tanktype =  "\multicolumn{1}{c}{No}"


eststo: reghdfe pricediff Less_st More_Fuel_st More_Other_st ///
	yearbuiltaudit_st conditionedsqft_st ///
	`not_extracted' wh_tanktype ///
	, ///
		vce(cl mlsid) absorb(yearbuiltcat saleyear lsaleyear )	

estadd scalar r2all = e(r2)


estadd local sample="\multicolumn{1}{c}{Main}"
estadd local dep_var = "\multicolumn{1}{c}{$\Delta$ P}"
estadd local stdzd = "\multicolumn{1}{c}{Yes}"
estadd local control_yblt_sqft =  "\multicolumn{1}{c}{Yes}"
estadd local control_not_extracted =  "\multicolumn{1}{c}{Yes}"
estadd local control_wh_tanktype =  "\multicolumn{1}{c}{Yes}"


local keepvars Less_st /// 
		 More_Fuel_st  ///
		 More_Other_st 
		 
esttab using "C:\Users\awcassidy1\Dropbox\jmp_new/tables/main_with_other_controls.tex", replace fragment ///
		keep(`keepvars') order(`keepvars') ///
		 label booktabs nomtitles noobs se(4) b(4) ///
		scalars( ///
				"k \textbf{Controls:}" ///
					"control_yblt_sqft Yr Blt \& Sq Ft" ///
						"control_not_extracted Not Extracted" ///
						"control_wh_tanktype WH Tank Type" ///
					"n \hline \vspace{\adjust}" ///
				"r2all R-squared" ///
		 "N Observations"  ///
				) ///
				sfmt( 0 0 0 0 0 %9.3fc %9.0fc  %9.0fc ) star(* 0.10 ** 0.05 *** 0.01)

		

********************************************************************************
*Placebo plus 3 sale (Table 4)
********************************************************************************

eststo clear


*Placebo L
eststo: reghdfe new_pricediff_baseline  Less_st , absorb(yearbuiltcat saleyear new_lsaleyear_baseline) vce(cl mlsid)	

estadd scalar r2all = e(r2)

local b= _b[Less_st]
local implied_pretrend: di %9.3fc `b'
estadd local implied_pretrend_L="`implied_pretrend'"



estadd local sample="\multicolumn{1}{c}{Placebo}"
estadd local dep_var = "\multicolumn{1}{c}{$\Delta$ P}"
estadd local stdzd = "\multicolumn{1}{c}{Yes}"



*3 sale L
eststo: reghdfe price pre_Less_st post_Less_st ///
	///
	pre saleneg1 post ///
	if bal_sample==1, ///
		vce(cl mlsid) absorb(yearbuiltcat#post saleyear#post mlsid )
				
local b= - _b[pre_Less_st]
local implied_pretrend: di %9.3fc `b'
estadd local implied_pretrend_L="`implied_pretrend'"
		
estadd scalar r2all = e(r2)

		
estadd local sample="\multicolumn{1}{c}{3-Sale}"
estadd local dep_var = "\multicolumn{1}{c}{P}"
estadd local stdzd = "\multicolumn{1}{c}{Yes}"


eststo: reghdfe new_pricediff_baseline   More_Fuel_st , absorb(yearbuiltcat saleyear new_lsaleyear_baseline) vce(cl mlsid)	

estadd scalar r2all = e(r2)



local b= _b[More_Fuel_st]
local implied_pretrend: di %9.3fc `b'
estadd local implied_pretrend_MF="`implied_pretrend'"


estadd local sample="\multicolumn{1}{c}{Placebo}"
estadd local dep_var = "\multicolumn{1}{c}{$\Delta$ P}"
estadd local stdzd = "\multicolumn{1}{c}{Yes}"


*3 sale MF
eststo: reghdfe price pre_More_Fuel_st post_More_Fuel_st ///
	///
	pre saleneg1 post ///
	if bal_sample==1, ///
		vce(cl mlsid) absorb(yearbuiltcat#post saleyear#post mlsid )
				
local b= - _b[pre_More_Fuel_st]
local implied_pretrend: di %9.3fc `b'
estadd local implied_pretrend_MF="`implied_pretrend'"
		
estadd scalar r2all = e(r2)

		
estadd local sample="\multicolumn{1}{c}{3-Sale}"
estadd local dep_var = "\multicolumn{1}{c}{P}"

estadd local stdzd = "\multicolumn{1}{c}{Yes}"

*placebo more other
eststo: reghdfe new_pricediff_baseline   More_Other_st, absorb(yearbuiltcat saleyear new_lsaleyear_baseline) vce(cl mlsid)	

estadd scalar r2all = e(r2)



local b=  _b[More_Other_st]
local implied_pretrend: di %9.3fc `b'
estadd local implied_pretrend_MO="`implied_pretrend'"



estadd local sample="\multicolumn{1}{c}{Placebo}"
estadd local dep_var = "\multicolumn{1}{c}{$\Delta$ P}"
estadd local stdzd = "\multicolumn{1}{c}{Yes}"



*3 sale MO
eststo: reghdfe price pre_More_Other_st post_More_Other_st ///
	///
	pre saleneg1 post ///
	if bal_sample==1, ///
		vce(cl mlsid) absorb(yearbuiltcat#post saleyear#post mlsid )
				
local b= - _b[pre_More_Other_st]
local implied_pretrend: di %9.3fc `b'
estadd local implied_pretrend_MO="`implied_pretrend'"
		
estadd scalar r2all = e(r2)

		
estadd local sample="\multicolumn{1}{c}{3-Sale}"
estadd local dep_var = "\multicolumn{1}{c}{P}"
estadd local stdzd = "\multicolumn{1}{c}{Yes}"

*placebo all

eststo: reghdfe new_pricediff_baseline  Less_st More_Fuel_st More_Other_st, absorb(yearbuiltcat saleyear new_lsaleyear_baseline) vce(cl mlsid)	

estadd scalar r2all = e(r2)

local b= _b[Less_st]
local implied_pretrend: di %9.3fc `b'
estadd local implied_pretrend_L="`implied_pretrend'"

local b=  _b[More_Other_st]
local implied_pretrend: di %9.3fc `b'
estadd local implied_pretrend_MO="`implied_pretrend'"

local b= _b[More_Fuel_st]
local implied_pretrend: di %9.3fc `b'
estadd local implied_pretrend_MF="`implied_pretrend'"


estadd local sample="\multicolumn{1}{c}{Placebo}"
estadd local dep_var = "\multicolumn{1}{c}{$\Delta$ P}"
estadd local stdzd = "\multicolumn{1}{c}{Yes}"


local keepvars Less_st /// 
		 More_Fuel_st  ///
		 More_Other_st 
		 


local keepvars Less_st  pre_Less_st  ///
		 post_Less_st ///
		 More_Fuel_st  pre_More_Fuel_st  ///
		 post_More_Fuel_st ///
		 More_Other_st  pre_More_Other_st  ///
		 post_More_Other_st

		
		 
esttab using "C:\Users\awcassidy1\Dropbox\jmp_new/tables/placebo_plus_3sale.tex", replace fragment ///
		keep(`keepvars') order(`keepvars') ///
		 label booktabs nomtitles noobs se(4) b(4) ///
		scalars( ///
					"k \textbf{Implied Pre-trend:}" ///
					"implied_pretrend_L Less" ///
						"implied_pretrend_MF More-Fuel" ///
						"implied_pretrend_MO More-Other" ///
					"n \hline \vspace{\adjust}" ///
					"sample Sample" ///
						"dep_var Dep Var" ///
				"r2all R-squared" ///
				"N_clust `clustvarword' Clusters" "N Observations"  ///
				) ///
				sfmt( 0 0 0 0 0 0 0 %9.3fc %9.0fc  %9.0fc ) star(* 0.10 ** 0.05 *** 0.01)
